<?php
namespace app\index\model;

use think\Model;

class Recharge extends Model
{

    /**
     * 获取充值明细
     * @author hey_heyang(635870453@qq.com)
     */
    public function  getRechargeList($time_begin,$time_end){

        if($time_begin && $time_end){
            $time1 = date('Y-m-d H:i:s',strtotime($time_begin));
            $time2 = date('Y-m-d H:i:s',strtotime($time_end.'+ 1 day')-1);
            $where['r.date'] = array('between',$time1.','.date($time2));
        }elseif($time_begin){
            $where['r.date'] = array('>=',date('Y-m-d H:i:s',strtotime($time_begin)));
        }elseif($time_end){
            $where['r.date'] = array('<=',date('Y-m-d H:i:s',strtotime($time_end.'+ 1 day')-1));
        }

        $where['r.status'] = ['eq',2];
        $filed='r.money,r.date,m.username,m.mobile';
        $res=$this->alias('r')
            ->join('tf_member m','r.user_id=m.id')
            ->where($where)
            ->field($filed)
            ->limit(1000)
            ->order('r.id desc')
            ->select();
        $res= empty($res)?array():$res->toArray();
        $total= $this->alias('r')->where($where)->sum('money');
        $data['res'] = $res;
        $data['total'] = $total;
        return $data;
    }


}